package com.shchuangzhi.smartguard;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.util.AttributeSet;

import com.elvishew.xlog.XLog;
import com.shchuangzhi.smartguard.core.Consts;

/**
 * Created by j_hu on 5/4/17.
 */

public abstract class YesOrNoPreference extends DialogPreference {
    public YesOrNoPreference(Context ctx, AttributeSet attrs) {
        super(ctx, attrs);
    }

    @Override
    protected void onClick() {
        AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
        dialog.setTitle(this.getDialogTitle());
        dialog.setMessage(this.getDialogMessage());
        dialog.setCancelable(true);
        dialog.setPositiveButton(Consts.POSITIVE_BUTTON, new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dialog, int which)
            {
            OnPositiveButtonClick(getContext());
            }
        });

        dialog.setNegativeButton(Consts.NEGATIVE_BUTTON, new DialogInterface.OnClickListener()
        {
            @Override
            public void onClick(DialogInterface dlg, int which)
            {
                OnNegativeButtonClick(getContext());
                dlg.cancel();
            }
        });
        AlertDialog al = dialog.create();
        al.show();
    }

    protected abstract void OnPositiveButtonClick(Context ctx);

    protected abstract void OnNegativeButtonClick(Context ctx);
}
